<#assign title="">
<#assign description="">
<#assign copyright="">
<#assign company="">
<#assign author="">
<#assign since="">
package ${packageName};

/**
 * 
 * <p>Title: ${title}</p> 
 * 
 * <p>Description: ${description}</p> 
 * 
 * <p>Copyright: Copyright (c) ${copyright}</p> 
 * 
 * <p>Company: ${company}</p>
 * 
 * @author ${author}
 * @since  ${since}
 * @version 1.0
 */

import java.util.Map;
import java.util.HashMap;
import java.util.List;
import java.util.ArrayList;

import com.sunwayworld.common.utils.VCommList;
import com.sunwayworld.common.struts2.BaseAction;
<#foreach package in packages?if_exists>
import ${package};
</#foreach>

public class ${className} extends BaseAction {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	private ${interface.className} ${interface.className?uncap_first} = null;
	
	private ${valueObject.className} ${valueObject.className?uncap_first} = new ${valueObject.className}();

	@Override
	public String execute(){
		return toList();
	}

	/**
	 * 跳转到新增页面
	 * @return detail
	 */
	public String toCreate() {
		return "detail";
	}
	
	/**
	 * 跳转到更新页面
	 * @return detail
	 */
	public String toUpdate() {
		return toDetail();
	}
	
	/**
	 * 跳转到详细页面
	 * @return detail
	 */
	public String toDetail() {
		try{
			${valueObject.className?uncap_first} = ${interface.className?uncap_first}.get${valueObject.classNick}Detail(${valueObject.className?uncap_first}.get${valueObject.pkField.name?default(mid)?cap_first}());
		}catch(Exception ex){
			ex.printStackTrace();
		}
		return "detail";
	}
	
	/**
	 * 跳转到列表页面
	 * @return list
	 */
	public String toList() {
		try {
			Map<String, String> map = new HashMap<String, String>();
			map = getRenderParameters();
			VCommList vlist = ${interface.className?uncap_first}.get${valueObject.classNick}List(map, spage);
			request.setAttribute("vlist", vlist);
		} catch (Exception ex) {
			ex.printStackTrace();
		}
		return "list";
	}
	
	/**
	 * 新增 ${valueObject.className} ${valueObject.classNick}
	 * @return detail
	 */
	public String create() {
		try{
			${valueObject.className?uncap_first} = ${interface.className?uncap_first}.create${valueObject.classNick}(${valueObject.className?uncap_first});
		}catch(Exception ex){
			ex.printStackTrace();
		}
		return toUpdate();
	}
	
	/**
	 * 更新 ${valueObject.className} ${valueObject.classNick}
	 * @return detail
	 */
	public String update() {
		try{
			${interface.className?uncap_first}.update${valueObject.classNick}(${valueObject.className?uncap_first});
		}catch(Exception ex){
			ex.printStackTrace();
		}
		return toUpdate();
	}
	
	/**
	 * 删除 List<${valueObject.className}> list<${valueObject.classNick}>
	 * @return list
	 */
	public String delete() {
		try {
			String[] chks = request.getParameterValues("chks");
			String[] ${valueObject.pkField.name?default(mid)?uncap_first}s = request.getParameterValues("${valueObject.pkField.name?default(mid)?uncap_first}s");
			if (null != chks) {
				List<${valueObject.className}> alist = new ArrayList<${valueObject.className}>();
				for (int i = 0, n = chks.length; i < n; i++) {
					${valueObject.className} info = new ${valueObject.className}();
					int index = Integer.valueOf(chks[i]);
					info.set${valueObject.pkField.name?default(mid)?cap_first}(Long.valueOf(${valueObject.pkField.name?default(mid)?uncap_first}s[index]));
					alist.add(info);
				}
				${interface.className?uncap_first}.delete${valueObject.classNick}s(alist);
			}

		} catch (Exception ex) {
			ex.printStackTrace();
		}
		return toList();
	}

	public void set${interface.className}(${interface.className} ${interface.className?uncap_first}){
		this.${interface.className?uncap_first} = ${interface.className?uncap_first};
	}
	
	public ${valueObject.className} get${valueObject.className}(){
		return this.${valueObject.className?uncap_first};
	}
	
	public void set${valueObject.className}(${valueObject.className} ${valueObject.className?uncap_first}){
		this.${valueObject.className?uncap_first} = ${valueObject.className?uncap_first};
	}
	
}
